package com.java.program_questions;

import java.util.Scanner;

/**
 * 问题：输入两个正整数m和n，求其最大公约数和最小公倍数
 * 分析：辗除法
 */
public class Question6 {
    // 求最大公约数
    public static int maxGongYueShu(int m, int n) {
        if (m == n) {
            System.out.println("最大公约数是" + m);
            return m;
        } else {
            int t = 0;
            if (n > m) {
                t = m;
                m = n;
                n = t;
            }
            while (n != 0) {
                t = m;
                m = n;
                n = t - n * (t / n);
            }
            System.out.println("最大公约数是" + m);
            return m;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入两数：");
        int m = sc.nextInt();
        int n = sc.nextInt();

        int max = maxGongYueShu(m, n);
        System.out.print("最小公倍数是" + m * n / max);
    }
}
